package com.janwen.spring.jdbc.template;

import java.util.Map;

import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import com.janwen.spring.jdbc.datasource.AbstractNamedParameterJdbcTemplate;


@Repository("namedParameterJdbcTemplateCase")
public class NamedParameterJdbcTemplateCase extends AbstractNamedParameterJdbcTemplate {

	
	public Long getLastId(){
		return getLastInsertId();
	}
	
	
	public int queryForInt(String sql,
            Map<String,?> paramMap,SqlParameterSource paramSource){
		if(paramSource == null){
			return getNamedParameterJdbcTemplate().queryForInt(sql, paramMap);
		}else{
			return getNamedParameterJdbcTemplate().queryForInt(sql, paramSource);
		}
		
	}
	
	/**
	 * in语句只能使用namedParameterJdbcTemplate,并且参数必须使用集合类,不能使用'1,2,3'
	 * 否则Warning:
	 * -SQLWarning ignored: SQL state '01000', error code '1265', message [Data truncated for column 'area_parent_id' at row 1]
[DEBUG]	2012-08-15 11:24:51,942	[main]	jdbc.core.JdbcTemplate	(JdbcTemplate.java:1319)	-
SQLWarning ignored: SQL state 'HY000', error code '1292', message [Truncated incorrect DOUBLE value: '1,3']
	 * janwen
	 * @param sql
	 * @param paramMap
	 * @return
	 *
	 */
	public int queryForIntWithIn(String sql,
            Map<String,?> paramMap){
		return getNamedParameterJdbcTemplate().queryForInt(sql, paramMap);
	}
}
